# database operations like softdelete
module Db
  # database operations like softdelete
  module Operations
    def self.included(base)
      base.send :include, InstanceMethods
      base.extend ClassMethods
    end

    # instance Methode
    module InstanceMethods
      def soft_delete
        self.deleted = true
        save!
      end
    end

    # class Methode
    module ClassMethods
      def feed(num)
        p "#{num} of #{name.underscore} has been created!"
        (1..num).each do
          obj = Fabricate(name.underscore.to_sym)
          obj.save!
        end
      end

      def clear_feed
        objs = where(is_mock: true)
        p "#{objs.size} of #{name.underscore} has been destroyed!"
        objs.each(&:destroy!)
      end
    end
  end
end
